/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package doc2db.interfaces.action.templates;

import doc2db.Keey;
import doc2db.UserProp;
import doc2db.fileWorker.FileBeginer;
import doc2db.fileWorker.FileIO;
import doc2db.interfaces.xmledit.XmlEditorFrame;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;

/**
 *
 * @author yuriy
 */
public class CorectTemplatesAction implements ActionListener{

    @Override
    public void actionPerformed(ActionEvent e) {
        final String s = FileBeginer.resurse_users_usersFolder + Keey.sp +
                UserProp.user + Keey.sp;
        final XmlEditorFrame f = new XmlEditorFrame(FileIO.readFromFiles(s + FileBeginer.templatesName),
                FileIO.readFromFiles(s + FileBeginer.metaTemplatesName), false);
        f.setSaveAction(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int ret = JOptionPane.showConfirmDialog(null, "Сохранить ?",
                    "Подтверждение", JOptionPane.YES_NO_OPTION);
                if (ret == JOptionPane.OK_OPTION) {
                    FileIO.createFile(f.text1.getText(), s+FileBeginer.templatesName);
                    FileIO.createFile(f.text2.getText(), s+FileBeginer.metaTemplatesName);
                }
            }
        });
        f.setVisible(true);
    }

}
